package com.xian.im.message.producer;

import java.util.HashMap;
import java.util.Map;
import java.util.ServiceLoader;

/**
 * @program: xian-im-server
 * @description:  消息生产者工厂类
 * @author: liru.xian
 * @create: 2021-03-01 09:34
 **/
public class MessageQueueProducerFactory {


    private static Map<Integer, MessageProducer> contextMap = new HashMap<>();

    static {
        ServiceLoader<MessageProducer> loader = ServiceLoader.load(MessageProducer.class);
        for (MessageProducer producer : loader) {
            contextMap.put(producer.getType(),producer);
        }
    }

    /**
     * 获取对应的处理对象
     * @param type
     * @return
     */
    public static MessageProducer getProdecer(Integer type){
        return contextMap.get(type);
    }
}
